using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Serialization;
using System.Net;

namespace JoinMe
{
    public partial class Password : Form
    {
        public Password()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.label6.Visible = false;
            this.label3.Visible = false;
            this.btnOK.Visible = false;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            IPEndPoint ep = IsolatedStorage.DecryptIPEndPoint(this.textBox1.Text);
            IsolatedStorage.SetIPEndPoint(ep);
            this.Close();
        }

        private void textBox1_Validating(object sender, CancelEventArgs e)
        {
            if (!String.IsNullOrEmpty(this.textBox1.Text))
            {
                try
                {
                    IPEndPoint ep = IsolatedStorage.DecryptIPEndPoint(this.textBox1.Text);
                    this.label6.Visible = true;
                    this.label6.ForeColor = Color.Green;
                    this.label6.Text = "Good password";
                    this.btnOK.Visible = true;
                    this.label3.Visible = true;
                }
                catch (Exception)
                {
                    this.label6.Visible = true;
                    this.label6.ForeColor = Color.Red;
                    this.label6.Text = "Bad password";
                }
            }
        }
    }
}